package com.cloud.lawcase.common.utils;

import java.util.Date;
import java.util.Map;

import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
import io.jsonwebtoken.SignatureAlgorithm;

public class JwtTokenHelper {

	private static final String SECRET = "E7025B7459A511E9875600FF21ED0826";

	public static String parserClaims(String token) {
		String appId = null;
		try {
			Claims claims = Jwts.parser().setSigningKey(SECRET).parseClaimsJws(token).getBody();
			appId = claims.get("APPID", String.class);
		} catch (Exception e) {
			throw new RuntimeException("无效的token");
		}
		return appId;
	}

	public static String generateToken(Map<String, Object> claims, Date exparDate) {
		return Jwts.builder().setClaims(claims).setIssuer("Q").setSubject("L").setIssuedAt(new Date()).setExpiration(exparDate)
				.signWith(SignatureAlgorithm.HS512, SECRET).compact();
	}

}
